﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Diagnostics;



// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace MetroTipi
{
    public sealed partial class PreferencesUserControl : UserControl, INotifyPropertyChanged
    {

        private String _identifiant;

        /*[Display(Name = "login", ResourceType = typeof(TipiFieldsResources))]*/
        public String Identifiant
        {
            get { return _identifiant; }
            set
            {
                ApplicationData.Current.RoamingSettings.Values["Identifiant"] = value;
                _identifiant = value;
                RaisePropertyChanged("Identifiant");                
                //SetProperty(ref this._identifiant, value);  
                
            }
        }

        private String _password;

        /*[Display(Name = "password", ResourceType = typeof(TipiFieldsResources))]*/
        public String Password
        {
            get { return _password; }
            set
            {
                ApplicationData.Current.RoamingSettings.Values["Password"] = value;
                _password = value;
                RaisePropertyChanged("Password");                
            }
        }

        public PreferencesUserControl()
        {
            this.InitializeComponent();

            if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("Identifiant"))
                Identifiant = (String)ApplicationData.Current.RoamingSettings.Values["Identifiant"];            

            if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("Password"))
                Password = (String)ApplicationData.Current.RoamingSettings.Values["Password"];                      
        }


        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;        

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        //protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
        //{
        //    if (object.Equals(storage, value)) return false;

        //    storage = value;
        //    this.OnPropertyChanged(propertyName);
        //    return true;
        //}
        
        //protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        //{
        //    var eventHandler = this.PropertyChanged;
        //    if (eventHandler != null)
        //    {
        //        eventHandler(this, new PropertyChangedEventArgs(propertyName));
        //    }
        //}
        #endregion
    }
}
